Fix build with imgui 1.92
authorTimo Röhling <roehling@debian.org>
Mon, 1 Sep 2025 15:22:56 +0000 (17:22 +0200)
committerTimo Röhling <roehling@debian.org>
Thu, 4 Sep 2025 11:57:31 +0000 (13:57 +0200)
Gbp-Pq: Name 0023-Fix-build-with-imgui-1.92.patch

libs/filagui/src/ImGuiHelper.cpp
libs/viewer/src/SimpleViewer.cpp

index 91b2a4e15669ab1374df21f39a9e212b697a51ca..8b2d131a28fc833c4799248ed26695761b91aa6f 100644 (file)
@@ -217,9 +217,9 @@ void ImGuiHelper::processImGuiCommands(ImDrawData* commands, const ImGuiIO& io)
                 materialInstance->setScissor( pcmd.ClipRect.x, fbheight - pcmd.ClipRect.w,
                         (uint16_t) (pcmd.ClipRect.z - pcmd.ClipRect.x),
                         (uint16_t) (pcmd.ClipRect.w - pcmd.ClipRect.y));
-                if (pcmd.TextureId) {
+                if (pcmd.GetTexID()) {
                     TextureSampler sampler(MinFilter::LINEAR, MagFilter::LINEAR);
-                    materialInstance->setParameter("albedo", (Texture const*)pcmd.TextureId, sampler);
+                    materialInstance->setParameter("albedo", (Texture const*)pcmd.GetTexID(), sampler);
                 }
                 rbuilder
                         .geometry(primIndex, RenderableManager::PrimitiveType::TRIANGLES,
index ec780138af59c6fe47fa38e5c25c9c38ab9c142f..2e774a66af45ddcd76015e067e60aa7693c26390 100644 (file)
@@ -94,6 +94,48 @@ static float getRangePlotValue(int series, void* data, int index) {
     return ((float*) data)[series * 1024 + index];
 }
 
+static ImGuiKey keyCodeToImGui(int keyCode)
+{
+    switch (keyCode) {
+        case 8:
+            return ImGuiKey_Backspace;
+        case 9:
+            return ImGuiKey_Tab;
+        case 13:
+            return ImGuiKey_Enter;
+        case 27:
+            return ImGuiKey_Escape;
+        case 35:
+            return ImGuiKey_End;
+        case 36:
+            return ImGuiKey_Home;
+        case 37:
+            return ImGuiKey_LeftArrow;
+        case 38:
+            return ImGuiKey_UpArrow;
+        case 39:
+            return ImGuiKey_RightArrow;
+        case 40:
+            return ImGuiKey_DownArrow;
+        case 46:
+            return ImGuiKey_Delete;
+        case 65:
+            return ImGuiKey_A;
+        case 67:
+            return ImGuiKey_C;
+        case 86:
+            return ImGuiKey_V;
+        case 88:
+            return ImGuiKey_X;
+        case 89:
+            return ImGuiKey_Y;
+        case 90:
+            return ImGuiKey_Z;
+        default:
+            return ImGuiKey_None;
+    }
+}
+
 inline float3 curves(float3 v, float3 shadowGamma, float3 midPoint, float3 highlightScale) {
     float3 d = 1.0f / (pow(midPoint, shadowGamma - 1.0f));
     float3 dark = pow(v, shadowGamma) * d;
@@ -426,26 +468,6 @@ void SimpleViewer::renderUserInterface(float timeStepInSeconds, View* guiView, f
 
         auto& io = ImGui::GetIO();
 
-        // The following table uses normal ANSI codes, which is consistent with the keyCode that
-        // comes from a web "keydown" event.
-        io.KeyMap[ImGuiKey_Tab] = 9;
-        io.KeyMap[ImGuiKey_LeftArrow] = 37;
-        io.KeyMap[ImGuiKey_RightArrow] = 39;
-        io.KeyMap[ImGuiKey_UpArrow] = 38;
-        io.KeyMap[ImGuiKey_DownArrow] = 40;
-        io.KeyMap[ImGuiKey_Home] = 36;
-        io.KeyMap[ImGuiKey_End] = 35;
-        io.KeyMap[ImGuiKey_Delete] = 46;
-        io.KeyMap[ImGuiKey_Backspace] = 8;
-        io.KeyMap[ImGuiKey_Enter] = 13;
-        io.KeyMap[ImGuiKey_Escape] = 27;
-        io.KeyMap[ImGuiKey_A] = 65;
-        io.KeyMap[ImGuiKey_C] = 67;
-        io.KeyMap[ImGuiKey_V] = 86;
-        io.KeyMap[ImGuiKey_X] = 88;
-        io.KeyMap[ImGuiKey_Y] = 89;
-        io.KeyMap[ImGuiKey_Z] = 90;
-
         // TODO: this is not the best way to handle high DPI in ImGui, but it is fine when using the
         // proggy font. Users need to refresh their window when dragging between displays with
         // different pixel ratios.
@@ -465,25 +487,26 @@ void SimpleViewer::mouseEvent(float mouseX, float mouseY, bool mouseButton, floa
         bool control) {
     if (mImGuiHelper) {
         ImGuiIO& io = ImGui::GetIO();
-        io.MousePos.x = mouseX;
-        io.MousePos.y = mouseY;
-        io.MouseWheel += mouseWheelY;
-        io.MouseDown[0] = mouseButton != 0;
-        io.MouseDown[1] = false;
-        io.MouseDown[2] = false;
+        io.AddMousePosEvent(mouseX, mouseY);
+        io.AddMouseWheelEvent(0, mouseWheelY);
+        io.AddMouseButtonEvent(0, mouseButton);
         io.KeyCtrl = control;
     }
 }
 
 void SimpleViewer::keyDownEvent(int keyCode) {
-    if (mImGuiHelper && keyCode < IM_ARRAYSIZE(ImGui::GetIO().KeysDown)) {
-        ImGui::GetIO().KeysDown[keyCode] = true;
+    if (mImGuiHelper) {
+        ImGuiKey key = keyCodeToImGui(keyCode);
+        if (key != ImGuiKey_None)
+            ImGui::GetIO().AddKeyEvent(key, true);
     }
 }
 
 void SimpleViewer::keyUpEvent(int keyCode) {
-    if (mImGuiHelper && keyCode < IM_ARRAYSIZE(ImGui::GetIO().KeysDown)) {
-        ImGui::GetIO().KeysDown[keyCode] = false;
+    if (mImGuiHelper) {
+        ImGuiKey key = keyCodeToImGui(keyCode);
+        if (key != ImGuiKey_None)
+            ImGui::GetIO().AddKeyEvent(key, false);
     }
 }